package com.hniu.mapu.utils;

import lombok.SneakyThrows;

import java.math.BigInteger;
import java.security.MessageDigest;

/**
 * 直接使用PasswordEncodeUtils.encoder("加密内容") 就可以实现加密
 * @author 惜
 */
public class PasswordEncodeUtils {


    @SneakyThrows
    public static String encoder(String password) {
        MessageDigest md5 = null;
        byte[] digest = MessageDigest.getInstance("md5").digest(password.getBytes("utf-8"));
        String md5code = new BigInteger(1, digest).toString(16);
        // 如果生成数字未满32位，需要前面补0
        for (int i = 0; i < 32 - md5code.length(); i++) {
            md5code = "0" + md5code;
        }
        return md5code;
    }
}
